public class LeetCode977 {
    public int[] sortedSquares(int[] nums) {
        int[] arr = new int[nums.length];
        int start = 0;
        int end = nums.length - 1;
        int n = nums.length - 1;


        while (n >= 0){
            int startNum = nums[start] * nums[start];
            int endNum = nums[end] * nums[end];
            if (startNum > endNum){
                arr[n] = startNum;
                start++;
            }else{
                arr[n] = endNum;
                end--;
            }
            n--;

        }
        return arr;
    }
}
